<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of sectionControl
 *
 * @author Chris Sim
 */
class sectionControl extends CWidget {
//put your code here

    public $htmlOptions = array();

    public function init() {
        parent::init();
        $id=$this->getId();
        $this->htmlOptions['id']=$id;
        if(empty($this->htmlOptions['class']))
            $this->htmlOptions['class'] = 'sectionControl';


        echo CHtml::openTag('div',$this->htmlOptions)."\n";
        $js =<<<EOP
$("#{$id}:parent").hover(function(){ $("#{$id}").slideDown(500);},function(){ $("#{$id}").slideUp(500);});
EOP;
        if(Yii::app()->request->isAjaxRequest)
            echo CHtml::script($js);
        else
            $this->publishAssets($id, $js);
    }
    public function run() {
    //make control
    //
        echo CHtml::closeTag('div');
    }

    private function publishAssets($id,$js='') {
        $baseUrl = Yii::getPathOfAlias('application.widgets.sectionControl.script');
        $publishurl = Yii::app()->getAssetManager()->publish($baseUrl);
        $cs = Yii::app()->getClientScript();

        $cs->registerCoreScript('jquery');
        $cs->registerCssFile($publishurl.'/sectionControl.css');

        if(!empty($js)) {
            $cs->registerScript(__CLASS__.'#'.$id, $js, CClientScript::POS_READY);
        }
    }
}
?>
